package ar.com.contable.ganancias.editor;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.ui.part.ViewPart;

import ar.com.contable.ganancias.listener.FoldersContentProvider;
import ar.com.contable.ganancias.listener.ItemCellModifier;
import ar.com.contable.ganancias.listener.TableLabelProvider;
import ar.com.contable.ganancias.modelVO.VOFactory;
import ar.com.contable.ganancias.modelVO.YearModelVO;
import ar.com.contable.ganancias.util.Consts;




public class View extends ViewPart {

	public static final String ID = "ar.com.contable.ganancias.editor.view";
	private TreeViewer m_treeViewer;

	public void createPartControl(Composite parent) {
		parent.setLayout(new FillLayout());

		Tree addressTree = new Tree(parent, SWT.H_SCROLL | SWT.V_SCROLL
				| SWT.BORDER);
		addressTree.setHeaderVisible(true);
		m_treeViewer = new TreeViewer(addressTree);

		m_treeViewer.setColumnProperties(new String[] { Consts.DETALLE, Consts.ENERO, Consts.FEBRERO, Consts.MARZO,
				Consts.ABRIL, Consts.MAYO, Consts.JUNIO, Consts.JULIO, Consts.AGOSTO, Consts.SEPTIEMBRE, 
				Consts.OCTUBRE, Consts.NOVIEMBRE, Consts.DICIEMBRE});

		addressTree.setLinesVisible(true);

		addressTree.setLayoutData(new GridData(GridData.FILL, GridData.FILL,
				true, true));

		addressTree.setRedraw(true);
		addressTree.setVisible(true);

		TreeColumn column1 = new TreeColumn(addressTree, SWT.LEFT);
		column1.setAlignment(SWT.LEFT);
		column1.setText("Detalle");
		column1.setWidth(300);
		TreeColumn columnJunary = new TreeColumn(addressTree, SWT.RIGHT);
		columnJunary.setAlignment(SWT.LEFT);
		columnJunary.setText("Enero");
		columnJunary.setWidth(85);
		TreeColumn columnFebrary = new TreeColumn(addressTree, SWT.RIGHT);
		columnFebrary.setAlignment(SWT.LEFT);
		columnFebrary.setText("Febrero");
		columnFebrary.setWidth(85);
		TreeColumn columnMarch = new TreeColumn(addressTree, SWT.RIGHT);
		columnMarch.setAlignment(SWT.LEFT);
		columnMarch.setText("Marzo");
		columnMarch.setWidth(85);
		TreeColumn columnAphil = new TreeColumn(addressTree, SWT.RIGHT);
		columnAphil.setAlignment(SWT.LEFT);
		columnAphil.setText("Abril");
		columnAphil.setWidth(85);
		TreeColumn columnMay = new TreeColumn(addressTree, SWT.RIGHT);
		columnMay.setAlignment(SWT.LEFT);
		columnMay.setText("Mayo");
		columnMay.setWidth(85);
		TreeColumn columnJune = new TreeColumn(addressTree, SWT.RIGHT);
		columnJune.setAlignment(SWT.LEFT);
		columnJune.setText("Junio");
		columnJune.setWidth(85);
		TreeColumn columnJuly = new TreeColumn(addressTree, SWT.RIGHT);
		columnJuly.setAlignment(SWT.LEFT);
		columnJuly.setText("Julio");
		columnJuly.setWidth(85);
		TreeColumn columnAugust = new TreeColumn(addressTree, SWT.RIGHT);
		columnAugust.setAlignment(SWT.LEFT);
		columnAugust.setText("Agosto");
		columnAugust.setWidth(85);
		TreeColumn columnSeptember = new TreeColumn(addressTree, SWT.RIGHT);
		columnSeptember.setAlignment(SWT.LEFT);
		columnSeptember.setText("Septiembre");
		columnSeptember.setWidth(85);
		TreeColumn columnOctober = new TreeColumn(addressTree, SWT.RIGHT);
		columnOctober.setAlignment(SWT.LEFT);
		columnOctober.setText("Octubre");
		columnOctober.setWidth(85);
		TreeColumn columnNovember = new TreeColumn(addressTree, SWT.RIGHT);
		columnNovember.setAlignment(SWT.LEFT);
		columnNovember.setText("Noviembre");
		columnNovember.setWidth(85);
		TreeColumn columnDecember = new TreeColumn(addressTree, SWT.RIGHT);
		columnDecember.setAlignment(SWT.LEFT);
		columnDecember.setText("Diciembre");
		columnDecember.setWidth(85);
		
		m_treeViewer.setContentProvider(new FoldersContentProvider(this));
		m_treeViewer.setLabelProvider(new TableLabelProvider(this));
//		
//		final IWorkbench workbench = PlatformUI.getWorkbench();
//		workbench.getwaddResourceChangeListener(new TodoAdapterFactory());
//		List<City> cities = new ArrayList<City>();
//		cities.add(new City(this));
//		m_treeViewer.setInput(cities);
		
		YearModelVO modelVO = VOFactory.createInstance("Gonzalez", "Julian");
		m_treeViewer.setInput(modelVO);
		m_treeViewer.expandAll();
		
//		m_treeViewer.get
		CellEditor[] editors = new CellEditor[13];
	    editors[0] = new TextCellEditor(m_treeViewer.getTree());
	    editors[1] = new TextCellEditor(m_treeViewer.getTree());
	    editors[2] = new TextCellEditor(m_treeViewer.getTree());
	    editors[3] = new TextCellEditor(m_treeViewer.getTree());
	    editors[4] = new TextCellEditor(m_treeViewer.getTree());
	    editors[5] = new TextCellEditor(m_treeViewer.getTree());
	    editors[6] = new TextCellEditor(m_treeViewer.getTree());
	    editors[7] = new TextCellEditor(m_treeViewer.getTree());	    
	    editors[8] = new TextCellEditor(m_treeViewer.getTree());
	    editors[9] = new TextCellEditor(m_treeViewer.getTree());
	    editors[10] = new TextCellEditor(m_treeViewer.getTree());
	    editors[11] = new TextCellEditor(m_treeViewer.getTree());
	    editors[12] = new TextCellEditor(m_treeViewer.getTree());
	    
		m_treeViewer.setCellEditors(editors);
		m_treeViewer.setCellModifier(new ItemCellModifier(m_treeViewer, modelVO.getModel()));
		

	}

	public void setFocus() {
		m_treeViewer.getControl().setFocus();
	}
}